<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * User
 *
 * @ORM\Table(name="User")
 * @ORM\Entity
 */
class User implements UserInterface
{

    /**
     * @ORM\ManyToMany(targetEntity="\App\Entity\Role")
     * @ORM\JoinTable(name="User_Groups_Role",
     *     joinColumns={@ORM\JoinColumn(name="groups", referencedColumnName="groups")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="role", referencedColumnName="id")}
     * )
     */
    private $roles; //每次更新数据库的时候需要把这一块注释掉//todo 后期查找解决方案


    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="account", type="string", length=50, unique=true)
     */
    private $account;

    /**
     * @var string
     *
     * @ORM\Column(name="password", type="string", length=36)
     */
    private $password;

    /**
     * @var string
     *
     * @ORM\Column(name="passwordPay", type="string", length=36)
     */
    private $passwordPay;

    /**
     * @var int
     *
     * @ORM\Column(name="addTime", type="integer")
     */
    private $addTime;

    /**
     * @var int
     *
     * @ORM\Column(name="lastLoginTime", type="integer")
     */
    private $lastLoginTime = 0;

    /**
     * @var string
     *
     * @ORM\Column(name="lastLoginIp", type="string", length=20)
     */
    private $lastLoginIp = "";

    /**
     * @var string
     *
     * @ORM\Column(name="headPic", type="string", length=255)
     */
    private $headPic = "";

    /**
     * @var string
     *
     * @ORM\Column(name="nickName", type="string", length=255)
     */
    private $nickName ="";

    /**
     * @var string
     *
     * @ORM\Column(name="phone", type="string", length=20)
     */
    private $phone = "";

    /**
     * @var string
     *
     * @ORM\Column(name="email", type="string", length=255)
     */
    private $email = "";

    /**
     * @var string
     *
     * @ORM\Column(name="qq", type="string", length=255)
     */
    private $qq = "";

    /**
     * @var string
     *
     * @ORM\Column(name="wechat", type="string", length=255)
     */
    private $wechat = "";

    /**
     * @var string
     *
     * @ORM\Column(name="wechatCode", type="string", length=10)
     */
    private $wechatCode = "";

    /**
     * @var string
     *
     * @ORM\Column(name="openid", type="string", length=255)
     */
    private $openid = "";

    /**
     * @var string
     *
     * @ORM\Column(name="alipay", type="string", length=255)
     */
    private $alipay = "";

    /**
     * @var string
     *
     * @ORM\Column(name="realName", type="string", length=255)
     */
    private $realName = "";

    /**
     * @var string
     *
     * @ORM\Column(name="idCard", type="string", length=30)
     */
    private $idCard = "";

    /**
     * @var int
     *
     * @ORM\Column(name="groups", type="integer")
     */
    private $groups = 1;

    /**
     * @var int
     *
     * @ORM\Column(name="level", type="integer")
     */
    private $level = 0;

    /**
     * @var string
     *
     * @ORM\Column(name="parent", type="string", length=20)
     */
    private $parent = 0;

    /**
     * @var int
     *
     * @ORM\Column(name="money", type="integer")
     */
    private $money = 0;

    /**
     * @var int
     *
     * @ORM\Column(name="coin", type="integer")
     */
    private $coin = 0;

    /**
     * @var int
     *
     * @ORM\Column(name="ban", type="integer")
     */
    private $ban = 0;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set account
     *
     * @param string $account
     *
     * @return User
     */
    public function setAccount($account)
    {
        $this->account = $account;

        return $this;
    }

    /**
     * Get account
     *
     * @return string
     */
    public function getAccount()
    {
        return $this->account;
    }

    /**
     * Set password
     *
     * @param string $password
     *
     * @return User
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Get password
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set passwordPay
     *
     * @param string $passwordPay
     *
     * @return User
     */
    public function setPasswordPay($passwordPay)
    {
        $this->passwordPay = $passwordPay;

        return $this;
    }

    /**
     * Get passwordPay
     *
     * @return string
     */
    public function getPasswordPay()
    {
        return $this->passwordPay;
    }

    /**
     * Set addTime
     *
     * @param integer $addTime
     *
     * @return User
     */
    public function setAddTime($addTime)
    {
        $this->addTime = $addTime;

        return $this;
    }

    /**
     * Get addTime
     *
     * @return int
     */
    public function getAddTime()
    {
        return $this->addTime;
    }

    /**
     * Set lastLoginTime
     *
     * @param integer $lastLoginTime
     *
     * @return User
     */
    public function setLastLoginTime($lastLoginTime)
    {
        $this->lastLoginTime = $lastLoginTime;

        return $this;
    }

    /**
     * Get lastLoginTime
     *
     * @return int
     */
    public function getLastLoginTime()
    {
        return $this->lastLoginTime;
    }

    /**
     * Set lastLoginIp
     *
     * @param string $lastLoginIp
     *
     * @return User
     */
    public function setLastLoginIp($lastLoginIp)
    {
        $this->lastLoginIp = $lastLoginIp;

        return $this;
    }

    /**
     * Get lastLoginIp
     *
     * @return string
     */
    public function getLastLoginIp()
    {
        return $this->lastLoginIp;
    }

    /**
     * Set headPic
     *
     * @param string $headPic
     *
     * @return User
     */
    public function setHeadPic($headPic)
    {
        $this->headPic = $headPic;

        return $this;
    }

    /**
     * Get headPic
     *
     * @return string
     */
    public function getHeadPic()
    {
        return $this->headPic;
    }

    /**
     * Set nickName
     *
     * @param string $nickName
     *
     * @return User
     */
    public function setNickName($nickName)
    {
        $this->nickName = $nickName;

        return $this;
    }

    /**
     * Get nickName
     *
     * @return string
     */
    public function getNickName()
    {
        return $this->nickName;
    }

    /**
     * Set phone
     *
     * @param string $phone
     *
     * @return User
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get phone
     *
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set qq
     *
     * @param string $qq
     *
     * @return User
     */
    public function setQq($qq)
    {
        $this->qq = $qq;

        return $this;
    }

    /**
     * Get qq
     *
     * @return string
     */
    public function getQq()
    {
        return $this->qq;
    }

    /**
     * Set wechat
     *
     * @param string $wechat
     *
     * @return User
     */
    public function setWechat($wechat)
    {
        $this->wechat = $wechat;

        return $this;
    }

    /**
     * Get wechat
     *
     * @return string
     */
    public function getWechat()
    {
        return $this->wechat;
    }

    /**
     * Set alipay
     *
     * @param string $alipay
     *
     * @return User
     */
    public function setAlipay($alipay)
    {
        $this->alipay = $alipay;

        return $this;
    }

    /**
     * Get alipay
     *
     * @return string
     */
    public function getAlipay()
    {
        return $this->alipay;
    }

    /**
     * Set realName
     *
     * @param string $realName
     *
     * @return User
     */
    public function setRealName($realName)
    {
        $this->realName = $realName;

        return $this;
    }

    /**
     * Get realName
     *
     * @return string
     */
    public function getRealName()
    {
        return $this->realName;
    }

    /**
     * Set idCard
     *
     * @param string $idCard
     *
     * @return User
     */
    public function setIdCard($idCard)
    {
        $this->idCard = $idCard;

        return $this;
    }

    /**
     * Get idCard
     *
     * @return string
     */
    public function getIdCard()
    {
        return $this->idCard;
    }

    /**
     * Set groups
     *
     * @param integer $groups
     *
     * @return User
     */
    public function setGroups($groups)
    {
        $this->groups = $groups;

        return $this;
    }

    /**
     * Get groups
     *
     * @return int
     */
    public function getGroups()
    {
        return $this->groups;
    }

    /**
     * Set level
     *
     * @param integer $level
     *
     * @return User
     */
    public function setLevel($level)
    {
        $this->level = $level;

        return $this;
    }

    /**
     * Get level
     *
     * @return int
     */
    public function getLevel()
    {
        return $this->level;
    }

    /**
     * Set parent
     *
     * @param string $parent
     *
     * @return User
     */
    public function setParent($parent)
    {
        $this->parent = $parent;

        return $this;
    }

    /**
     * Get parent
     *
     * @return string
     */
    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Set money
     *
     * @param integer $money
     *
     * @return User
     */
    public function setMoney($money)
    {
        $this->money = $money;

        return $this;
    }

    /**
     * Get money
     *
     * @return int
     */
    public function getMoney()
    {
        return $this->money;
    }

    /**
     * Set coin
     *
     * @param integer $coin
     *
     * @return User
     */
    public function setCoin($coin)
    {
        $this->coin = $coin;

        return $this;
    }

    /**
     * Get coin
     *
     * @return int
     */
    public function getCoin()
    {
        return $this->coin;
    }

    /**
     * Set ban
     *
     * @param integer $ban
     *
     * @return User
     */
    public function setBan($ban)
    {
        $this->ban = $ban;

        return $this;
    }

    /**
     * Get ban
     *
     * @return int
     */
    public function getBan()
    {
        return $this->ban;
    }

    /****************************Security**********************************/
    public function getRoles()
    {
        $roles = array();
        foreach ($this->roles as $role) {
            $roles[] = $role->getCode();
        }
        return $roles;
    }
    public function getSalt()
    {
        return null;
    }
    public function getUsername()
    {
        return $this->account;
    }
    public function eraseCredentials()
    {
    }


    /*****************my func*******************/
    public function toArray()
    {
        return array(
            "id" => $this->getId(),
            "account" => $this->account,
            "phone" => $this->phone,
            "headPic" => $this->headPic,
            "nickName" => $this->nickName,
            "email" => $this->email,
            "lastLoginIp" => $this->lastLoginIp,
            "lastLoginTime" => date("Y/m/d H:i:s",$this->lastLoginTime),
        );
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Set wechatCode
     *
     * @param string $wechatCode
     *
     * @return User
     */
    public function setWechatCode($wechatCode)
    {
        $this->wechatCode = $wechatCode;

        return $this;
    }

    /**
     * Get wechatCode
     *
     * @return string
     */
    public function getWechatCode()
    {
        return $this->wechatCode;
    }

    /**
     * Set openid
     *
     * @param string $openid
     *
     * @return User
     */
    public function setOpenid($openid)
    {
        $this->openid = $openid;

        return $this;
    }

    /**
     * Get openid
     *
     * @return string
     */
    public function getOpenid()
    {
        return $this->openid;
    }


    /**
     * Add role
     *
     * @param \App\Entity\Role $role
     *
     * @return User
     */
    public function addRole(\App\Entity\Role $role)
    {
        $this->roles[] = $role;

        return $this;
    }

    /**
     * Remove role
     *
     * @param \App\Entity\Role $role
     */
    public function removeRole(\App\Entity\Role $role)
    {
        $this->roles->removeElement($role);
    }
}
